# keepalived-install.sls

# 1. 安装 Keepalived 软件包
install_keepalived:
  pkg.installed:
    - name: keepalived

# 2. 配置文件管理（使用 Jinja 模板示例）
/etc/keepalived/keepalived.conf:
  file.managed:
    - source: salt://services/files/etc/keepalived/keepalived.conf  # 模板文件路径
    - template: jinja
    - context:
      # 配置参数示例（可通过 Pillar 覆盖）
      vrrp_instance_name: "VI_1"
      interface: "eth0"
      virtual_router_id: "51"
      priority: "100"
      virtual_ipaddress: "192.168.3.9/24"
      auth_pass: "your_auth_password"
    - require:
      - pkg: install_keepalived

# 3. 服务管理
keepalived_service:
  service.running:
    - name: keepalived
    - enable: True
    - watch:
      - file: /etc/keepalived/keepalived.conf  # 配置变更时重启服务
    - require:
      - pkg: install_keepalived
      - file: /etc/keepalived/keepalived.conf
